using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Collections.ObjectModel;

namespace DCControls
{
    public partial class DependencyGroupView : UserControl
    {
        private Size savedHeight;
        private Size collapsed;
        private Collection<DependencyTest.DependencyBase> dependencies;

        public DependencyGroupView()
        {
            InitializeComponent();
            savedHeight = this.Size;
            collapsed = new Size(savedHeight.Width, panel1.Size.Height);
        }

        public void Reset()
        {
            dependencies = null;
            flowLayoutPanel1.Controls.Clear();
        }
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            flowLayoutPanel1.Visible = !flowLayoutPanel1.Visible;
            if (flowLayoutPanel1.Visible)
            {
                pictureBox1.Image = global::DCControls.Properties.Resources.Expanded;
                this.Size = savedHeight;
            }
            else
            {
                pictureBox1.Image = global::DCControls.Properties.Resources.Collapsed;
                this.Size= collapsed;
            }
        }
        public bool AddDependency(DependencyTest.DependencyBase dependency)
        {
            if (dependencies == null)
            {
                dependencies = new Collection<DependencyTest.DependencyBase>();
            }
            dependencies.Add(dependency);

            int controlNumber=this.flowLayoutPanel1.Controls.Count+1;
            DCControls.DependencyViewControl newControl = new DCControls.DependencyViewControl();
            newControl.Dependency = dependency;
            //newControl.BackColor = System.Drawing.Color.Black;
            // Not needed because the flow layout will layout the control
            // newControl.Location = new System.Drawing.Point(3, 3);
            newControl.Name = "dependencyViewControl"+controlNumber.ToString();
            //newControl.Size = new System.Drawing.Size(524, 69);
            newControl.TabIndex = controlNumber-1;
            flowLayoutPanel1.Controls.Add(newControl);
            return newControl.DependencyStatus;
        }
        
        public Collection<DependencyTest.DependencyBase> Dependencies
        {
            get { return dependencies; }
            set { dependencies = value; }
        }

        public string Heading
        {
            get { return lblHeading.Text; }
            set { lblHeading.Text = value; }
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.DrawLine(new Pen(Color.Blue, 2), new Point(0, 9), new Point(panel1.Width, 9));

        }
    }
}
